import { history } from 'umi';

interface Params {
  [key: string]: any;
}

export const Routers = {
  index: '/',
  test: '/example/test',
  fluidWallpaper: '/example/fluidWallpaper',
  lottie: '/example/lottie',
  gsap: '/example/gsap',
  color: '/example/color',
  smoothScroll: '/example/smoothScroll',
  uiandae: '/example/uiandae',
  loadings: '/example/loadings',
  lumen2d: '/example/lumen2d',

  webgl: '/example/webgl',
  three: '/example/three',
  threeTest: '/example/threeTest',
  threeMath: '/example/threeMath',
  threeCsg: '/example/threeCsg',
  threePointsTest: '/example/threePointsTest',
  threeWavePoints: '/example/threeWavePoints',
  pointsGpu: '/example/pointsGpu',
  pointsAnimate: '/example/pointsAnimate',
  threeLoaders: '/example/threeLoaders',
  curve: '/example/curve',
  noise: '/example/noise',
  renderer: '/example/renderer',
  avatarInput: '/example/avatarInput',
  birdCage: '/example/birdCage',
  loading3d: '/example/loading3d',
  button3d: '/example/button3d',
  dayNightbuttons: '/example/dayNightbuttons',
  buttonLove: '/example/buttonLove',
  buttonColorful: '/example/buttonColorful',
  earthFlight: '/example/earthFlight',
  geminiSvg: '/example/geminiSvg',

  constructor: '/other/constructor',
};
export type Router = keyof typeof Routers;

export const Links = {
  douyinMy:
    'https://www.douyin.com/user/MS4wLjABAAAAL8nQTTzankgJ5vBjtxEvxEyy3AzGYuyt6V7qe5mcZSI',
  jianshuMy: 'https://www.jianshu.com/u/a6056719f332',
  csdnMy: 'https://blog.csdn.net/qq_25294327',
};
export type LinksType = keyof typeof Links;

function constructUrl(name: Router) {
  return Routers[name] || '/';
}

/**
 * 前进
 *
 * @param {Router} router
 * @param {Params} [params]
 * @returns
 */
function push(router: Router, params?: Params) {
  return history.push({
    pathname: constructUrl(router),
    query: params,
  });
}

/**
 * 外部链接
 * @param {LinksType} router
 */
function link(router: LinksType) {
  window.open(Links[router]);
  // return window.location.href = Links[router]
}

function back() {
  return history.goBack();
}

export default {
  back,
  history,
  params: history.location.query,
  push,
  link,
  // navigateTo,
  // reLaunch,
  // redirect,
  // redirectToWeapp,
  // handleAdRoute
};
